<template>
	<uni-popup ref="share" type="share" safeArea backgroundColor="#fff">
		<view style="display: flex; padding: 10px 10px 0 10px;align-items: center;">
			<img :src="bannner" alt="" style="width: 50px; height: 50px;">
			<text style="color: red; font-size: 40rpx">￥{{ props.good_date.g_price }}</text>
		</view>
		<view style="display: flex;align-items: center;" @tap="goPath">
			<img src="../../static/adds.png" alt="" style="width: 50rpx; height: 50rpx;">
			<view style="font-size: 30rpx; width: 90%;
                padding: 10px 20px;
                text-align: center;">{{ data.name + " " + data.phone + " " + data.city + data.detail }}
			</view>
		</view>
		<view style="    
            display: flex;
            justify-content: space-between;
            padding: 20px;
        ">
			<text>数量</text>
			<uni-number-box @change="changeValue" />
		</view>
		<view>
			<button style="
                background: linear-gradient(to left, #FF0000,#ff8800);
                color: #fff;
                border-radius: 20px;" @tap="payin">立即支付 ￥{{ props.good_date.g_price * num }}</button>
		</view>
	</uni-popup>
	<!-- 输入框示例 -->
	<uni-popup ref="inputDialog" type="dialog">
			<image src="../../static/zf.jpg" mode=""></image>
			<button style="
			    background: linear-gradient(to left, #FF0000,#ff8800);
			    color: #fff;
			    border-radius: 20px;" @tap="pay">立即支付 ￥{{ props.good_date.g_price * num }}</button>
	</uni-popup>
</template>
<script lang='ts' setup>
	import {
		ref
	} from "vue";
	import {
		addressListApi
	} from '../../https/http'
	import {
		onLoad,
		onReachBottom
	} from "@dcloudio/uni-app"
	const user = ref()
	const data = ref()
	const inputDialog = ref()
	const num = ref(1)

	type Props = {
		bannner: string
		good_date: {
			g_price: number
		}
	}
	const props = defineProps < Props > ()
	const emits = defineEmits < {
		(e: 'pay', data: {}): void
	} > ()
	const share = ref()
	const handelClick = async () => {
		await newData()
		share.value.open()
	}
	const closeClick = async () => {
		share.value.close()
	}
	const newData = async () => {
		const res = await addressListApi(user.value)
		if (res.code == 200) {
			res.data.forEach(e => {
				if (e.state == 1) {
					data.value = e
				}
			})
		}
	}
	const changeValue = (value: number) => {
		num.value = value
	}
	onLoad((e: any) => {
		try {
			const value = uni.getStorageSync('d_usern');
			if (value) {
				user.value = value
			}
		} catch (e) {
			// error
		}
	})
	const goPath = () => {
		uni.navigateTo({
			url: '/pages/my-path-list/my-path-list'
		})
	}
	// 确认付款
	const payin = () => {
		inputDialog.value.open()
	}
	// 确认付款
	const pay = () => {
		const d: any = {}
		d.goods = props.good_date
		d.user = data.value
		d.num = num.value
		emits('pay', d)
		inputDialog.value.close()
	}
	defineExpose({
		handelClick,
		closeClick
	});
</script>
<style lang='sass' scoped>
</style>